var config = require('../../../config');
var login = require('../../../login');

// 用户Member
var url = config.dsh.members.url;
var token = config.dsh.token;

// 沙龙salon
var salonUrl = config.dsh.salons.url;
var salon_member_id_url = config.dsh.salons.member_id_url;


// 图标
var icons = config.dsh.icons;


console.log('****func****')
login.func.check_member();
Page({
  data: {
    date_icon:icons.date_icon,
    lbs_icon:icons.lbs_icon,
    eye_icon:icons.eye_icon,
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 4000,
    duration: 500,
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/dev0818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/dev0818/tooopen_sy_175833047715.jpg'
    ],
    my_show:false,
    fb_show:false,
    name:'',
    mobile:'',
    email:'',
    salons:[], //沙龙列表
    page:1,//沙龙页码
    no_more:false

  },
  onLoad:function(){
    console.log('****获取沙龙信息****');
    var openid = wx.getStorageSync('openid');
    console.log('-----------------');
    console.log(openid);
    wx.showLoading({
      title: '加载中',
    });
    this.get_salons();
  },
  onPullDownRefresh: function () { //下拉刷新
    this.setData({
      salons:[]
    });
    wx.showLoading({
      title: '加载中',
    });
    this.get_salons();
  },
  onReachBottom: function(){ //下拉加载
    wx.showLoading({
      title: '加载中',
    });
    this.get_more();
  },
  salon_fb:function(){
    var member = this.get_member('salon_fb');
    if(member == ''){   
      // setTimeout(this.salon_fb(),100);
      return false;
    }
    console.log(member)
    // 发布沙龙
    this.setData({
      fb_show:true
    });
  },
  salon_input_done:function(e){
    console.log(e.detail.value);
  },
  salon_textarea_done: function(e){
    console.log(e.detail.value);
  },
  salon_submit:function(){
    // 这里要看跳转是什么
    var my_redirect = wx.getStorageSync('my_redirect');
    // 进行沙龙提交审核
    this.setData({
      fb_show:false
    });
  },
  closeSalon_fb: function(){
    this.setData({
      fb_show:false
    });
  },
  my_input_name:function(e){
    console.log(e.detail.value);
  },
  my_input_mobile:function(e){
    console.log(e.detail.value);
  },
  my_input_email:function(e){
    console.log(e.detail.value);
  },
  my_submit:function(){
    if(!this.data.name || !this.data.mobile || !this.data.email){
      this.alert_msg('请填写完整表单内容');
    }
  },
  alert_msg:function(msg){
    wx.showModal({
      title: '提示',
      content: msg,
      showCancel:false,
      success: function (res) {
        
      }
    })
  },
  closeMy:function(){
    this.setData({
      my_show:false
    });
  },
  get_member:function(my_redirect){//获取用户memeber表信息
    var member = wx.getStorageSync('member');
    console.log('*************member11***********');
    console.log(member);
    if (typeof (member) == 'undefined') {
      login.func.check_member();
    }else{//如果没有name、email、mobile
      console.log('*************member***********');
      console.log(member);
      this.setData({
        name:member.name,
        email:member.email,
        mobile:member.mobile
      });
      if (!member.name || !member.email || !member.mobile){
        this.setData({
          my_show:true
        });
        wx.setStorageSync('my_redirect', my_redirect);
        return false;
      }
    }
    return (typeof(member) == 'undefined') ? '' : member;
  },
  get_salons:function(){
    const _this = this;
    console.log('*****正在获取沙龙信息*****');
    wx.request({
      url: salonUrl + '&page=' + this.data.page,
      success:function(res){
        console.log(res);
        var salons = _this.data.salons;
        for(var i = 0; i < res.data.length ; i++){
          // if(res.data[i].status == 1){
          //   salons.push(res.data[i]);
          // }
          salons.push(res.data[i]);
        }
        console.log('*****正在获取沙龙信息123456*****');
        console.log(salons);
        _this.setData({
          salons: salons
        });

        
        setTimeout(function(){
          wx.hideLoading();// 然后将loading去除
          wx.stopPullDownRefresh();// 将下拉刷新标志去除
        },500);
        

      },
      fail:function(e){
        console.log(e);
      },
      complete:function(e){
        console.log('沙龙结束');
      }
    })
  },
  get_more(){
    this.setData({
      page: this.data.page + 1
    });
    this.get_salons();
  }
})
